<template>
  <el-dialog
    :title="`${row.id ? '编辑' : '添加'}客服`"
    :visible.sync="visible"
    :close-on-click-modal="false"
    :before-close="handleCloseDialog"
    width="700px"
  >
    <el-form
      :model="dataObject"
      :rules="rules"
      ref="adminForm"
      label-width="130px"
      size="small"
    >
      <el-form-item label="客服名称：" prop="waiterName">
        <el-input
          v-model="dataObject.waiterName"
          placeholder="请输入客服名称"
          clearable
        ></el-input>
      </el-form-item>

      <el-form-item label="客服地址：" prop="waiterUrl">
        <el-input
          v-model="dataObject.waiterUrl"
          placeholder="请输入客服地址"
          clearable
        ></el-input>
      </el-form-item>
    </el-form>

    <span slot="footer" class="dialog-footer">
      <el-button
        type="primary"
        @click="handleConfirmDialog('adminForm')"
        size="mini"
        :loading="loading"
        >确 定</el-button
      >
      <el-button @click="handleCloseDialog" size="mini">取 消</el-button>
    </span>
  </el-dialog>
</template>
<script>
import { addServiceInfo, updateServiceInfo } from "@/api/config/index";
import { createNamespacedHelpers } from "vuex";
import { getMemberLickList } from "@/api/transaction/index";
const { mapState } = createNamespacedHelpers("service");
const defaultObject = {
  waiterName: "",
  waiterUrl: ""
};

export default {
  data() {
    return {
      visible: true,
      loading: false,
      remoteLoading: false,
      dataObject: Object.assign({}, defaultObject)
    };
  },
  props: {
    row: {
      type: Object,
      default: {}
    }
  },
  computed: {
    ...mapState({
      rules: state => state.rules
    })
  },
  mounted() {
    if (this.row.id) {
      this.getLoad();
    }
  },
  methods: {
    //初始化详情
    getLoad() {
      this.dataObject = { ...this.row };
    },
    handleCloseDialog() {
      this.$emit("handle-cancel");
    },
    handleConfirmDialog(formName) {
      this.$refs[formName].validate(async valid => {
        if (valid) {
          this.loading = true;
          let params = { ...this.dataObject };

          if (this.row.id) {
            await updateServiceInfo({ ...params, id: this.row.id });
          } else {
            await addServiceInfo(params);
          }
          this.loading = false;
          this.resetForm(formName);
          this.$message({
            message: `${this.row.id ? "新增" : "编辑"}成功`,
            type: "success",
            duration: 1000
          });
          this.$emit("handle-confirm");
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
      this.dataObject = Object.assign({}, defaultObject);
    },
    
  }
};
</script>
<style scoped></style>
